package com.godyao.mall.sms.controller;

import com.godyao.mall.core.model.ResultMsg;
import com.godyao.mall.core.utils.PageUtils;
import com.godyao.mall.sms.entity.SeckillSessionEntity;
import com.godyao.mall.sms.service.SeckillSessionService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;


/**
 * 秒杀活动场次
 *
 * @author godyao
 * @email godyao0801@qq.com
 * @date 2022-04-19 15:22:30
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("sms/seckillsession")
public class SeckillSessionController {

    private final SeckillSessionService seckillSessionService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public ResultMsg list(@RequestParam Map<String, Object> params){
        PageUtils page = seckillSessionService.queryPage(params);

        return ResultMsg.resultSuccess(page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public ResultMsg info(@PathVariable("id") Long id){
		SeckillSessionEntity seckillSession = seckillSessionService.getById(id);

        return ResultMsg.resultSuccess(seckillSession);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public ResultMsg save(@RequestBody SeckillSessionEntity seckillSession){
		seckillSessionService.save(seckillSession);

        return ResultMsg.resultSuccess("OK");
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public ResultMsg update(@RequestBody SeckillSessionEntity seckillSession){
		seckillSessionService.updateById(seckillSession);

        return ResultMsg.resultSuccess("OK");
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public ResultMsg delete(@RequestBody Long[] ids){
		seckillSessionService.removeByIds(Arrays.asList(ids));

        return ResultMsg.resultSuccess("OK");
    }

}
